package com.zahb.qadx.ui.fragment;

import android.view.View;
import android.widget.TextView;

import com.zahb.qadx.R;
import com.zahb.qadx.base.BaseFragmentExt;
import com.zahb.qadx.net.RetrofitService;
import com.zahb.qadx.ui.view.CircleImageView;
import com.zahb.qadx.util.Constant;
import com.zahb.qadx.util.ImageLoaderKt;
import com.zahb.qadx.util.Tips;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;


public class LecturerFragment extends BaseFragmentExt {

    @BindView(R.id.ivHead)
    CircleImageView ivHead;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvDes)
    TextView tvDes;
    @BindView(R.id.tvContent)
    TextView tvContent;

    @Override
    protected int getLayout() {
        return R.layout.fragment_lecturer;
    }

    @Override
    protected void initViews(View rootView) {
        mUnbinder = ButterKnife.bind(this, rootView);

        int teacherId = getArguments().getInt("teacherId", 0);
        if (teacherId <= 0) return;

        addDisposable(RetrofitService.getNetService()
                .getTeacherInfo(teacherId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(response -> {
                    if (response.getStatusCode() == Constant.CODE_SUCCESS) {

                        tvName.setText(response.getData().getName());
                        tvDes.setText(response.getData().getTitle());
                        tvContent.setText(response.getData().getBriefIntroduce());
                        ImageLoaderKt.loadImage(ivHead,response.getData().getHeadPhoto());
                    } else if (response.getStatusCode() != Constant.CODE_OFFLINE) {
                        showBindToast(response.getErrorInfo());
                    }
                }, throwable -> {
                    Tips.RequestError(getActivity());
                    throwable.printStackTrace();
                }));
    }
}
